package com.sk.z.khk.tdd;

import static org.junit.Assert.*;
import static org.hamcrest.core.Is.*;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.junit.Test;

public class Classifier1Test {
	// @Test
	// public void is_1_a_factor_of_10() {
	// assertTrue(new Classifier1(10).isFactor(1));
	// }
	private Integer[] PERFECT_NUMS = new Integer[] { 6, 28, 496, 8128 };

//	@Test
//	public void factors_for_6() {
//		Classifier1 c = new Classifier1(6);
//		c.calculateFactors();
//		assertThat(c.getFactors(), is(expectationSetWith(1, 2, 3, 6)));
//	}

	private Set<Integer> expectationSetWith(Integer... numbers) {
		return new HashSet<Integer>(Arrays.asList(numbers));
	}

//	@Test
//	public void factors_for_100() {
//		Classifier1 c = new Classifier1(100);
//		c.calculateFactors();
//		assertThat(c.getFactors(),
//				is(expectationSetWith(1, 100, 2, 50, 4, 25, 5, 20, 10)));
//	}

	@Test(expected = InvalidNumberException.class)
	public void cannot_classify_negative_numbers() {
		new Classifier1(-20);
	}

//	@Test
//	public void factors_for_max_int() {
//		Classifier1 c = new Classifier1(Integer.MAX_VALUE);
//		c.calculateFactors();
//		assertThat(c.getFactors(), is(expectationSetWith(1, 2147483647)));
//	}

	@Test
	public void test_a_bunch_of_numbers() {
		Set<Integer> expected = expectationSetWith(PERFECT_NUMS);
		for (int i = 2; i < 100000; i++) {
			if (expected.contains(i))
				assertTrue(classifierFor(i).isPerfect());
			else
				assertFalse(classifierFor(i).isPerfect());
		}
	}

	private Classifier1 classifierFor(int i) {
		return new Classifier1(i);
	}
}
